package elasticsearch

import (
	"fmt"
	"github.com/elastic/go-elasticsearch/v7"
	"github.com/zeromicro/go-zero/core/logx"
	"goods_srv/appconfig"
)

var Es *elasticsearch.Client

func Init() {
	var err error
	esInit := appconfig.AppConf.EsInit
	date := fmt.Sprintf("%s:%d", esInit.Host, esInit.Port)
	cfg := elasticsearch.Config{
		Addresses: []string{
			"http://" + date,
		},
		// ...
	}
	Es, err = elasticsearch.NewClient(cfg)
	if err != nil {
		panic(err)
	} else {
		logx.Info("Es init success")
	}
}
